package com.ihrm.system.dao;
import com.ihrm.domain.system.po.Permission;
import com.ihrm.domain.system.vo.PermissionResult;
import com.ihrm.domain.system.vo.PermissionResults;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 *  * 权限数据访问接口  
 */
public interface PermissionDao extends JpaRepository<Permission, String>, JpaSpecificationExecutor<Permission>
{
    @Query(value =
            "WITH RECURSIVE PermissionHierarchy AS ( " +
            "   SELECT * " +
            "   FROM pe_permission " +
            "   WHERE id = ?1 " +
            "   UNION ALL " +
            "   SELECT p.* " +
            "   FROM pe_permission p " +
            "   INNER JOIN PermissionHierarchy ph ON p.pid = ph.id " +
            "   WHERE p.pid IS NOT NULL " +
            ") " +
            "SELECT * FROM PermissionHierarchy", nativeQuery = true)
    List<Permission> findPermissionHierarchyById(String id);

    List<Permission> findByTypeAndPid(int permissionApi, String id);
}
